<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::FormHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionView::Helpers::FormHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/form_helper_rb.html">actionpack/lib/action_view/helpers/form_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Form helpers are designed to make working with resources much easier
compared to using vanilla <a href="../../HTML.html">HTML</a>.</p>

<p>Typically, a form designed to create or update a resource reflects the
identity of the resource in several ways: (i) the url that the form is sent
to (the form element’s <code>action</code> attribute) should result in a
request being routed to the appropriate controller action (with the
appropriate <code>:id</code> parameter in the case of an existing
resource), (ii) input fields should be named in such a way that in the
controller their values appear in the appropriate places within the
<code>params</code> hash, and (iii) for an existing record, when the form
is initially displayed, input fields corresponding to attributes of the
resource should show the current values of those attributes.</p>

<p>In <a href="../../Rails.html">Rails</a>, this is usually achieved by
creating the form using <code>form_for</code> and a number of related
helper methods. <code>form_for</code> generates an appropriate
<code>form</code> tag and yields a form builder object that knows the model
the form is about. Input fields are created by calling methods defined on
the form builder, which means they are able to generate the appropriate
names and default values corresponding to the model attributes, as well as
convenient IDs, etc. Conventions in the generated field names allow
controllers to receive form data nicely structured in <code>params</code>
with no effort on your side.</p>

<p>For example, to create a new person you typically set up a new instance of
<code>Person</code> in the <code>PeopleController#new</code> action,
<code>@person</code>, and in the view template pass that object to
<code>form_for</code>:</p>

<pre>&lt;%= form_for @person do |f| %&gt;
  &lt;%= f.label :first_name %&gt;:
  &lt;%= f.text_field :first_name %&gt;&lt;br /&gt;

  &lt;%= f.label :last_name %&gt;:
  &lt;%= f.text_field :last_name %&gt;&lt;br /&gt;

  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>The <a href="../../HTML.html">HTML</a> generated for this would be (modulus
formatting):</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">form</span> <span class="ruby-identifier">action</span>=<span class="ruby-string">&quot;/people&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;new_person&quot;</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;new_person&quot;</span> <span class="ruby-identifier">method</span>=<span class="ruby-string">&quot;post&quot;</span><span class="ruby-operator">&gt;</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">div</span> <span class="ruby-identifier">style</span>=<span class="ruby-string">&quot;margin:0;padding:0;display:inline&quot;</span><span class="ruby-operator">&gt;</span>
    <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;authenticity_token&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;hidden&quot;</span> <span class="ruby-identifier">value</span>=<span class="ruby-string">&quot;NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-regexp">/div&gt;
  &lt;label for=&quot;person_first_name&quot;&gt;First name&lt;/</span><span class="ruby-identifier">label</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">:</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_first_name&quot;</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;person[first_name]&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;text&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">&lt;</span><span class="ruby-identifier">br</span> <span class="ruby-regexp">/&gt;

  &lt;label for=&quot;person_last_name&quot;&gt;Last name&lt;/</span><span class="ruby-identifier">label</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">:</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_last_name&quot;</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;person[last_name]&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;text&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">&lt;</span><span class="ruby-identifier">br</span> <span class="ruby-regexp">/&gt;

  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Create Person&quot; /</span><span class="ruby-operator">&gt;</span>
<span class="ruby-operator">&lt;</span><span class="ruby-regexp">/form&gt;
</span></pre>

<p>As you see, the <a href="../../HTML.html">HTML</a> reflects knowledge about
the resource in several spots, like the path the form should be submitted
to, or the names of the input fields.</p>

<p>In particular, thanks to the conventions followed in the generated field
names, the controller gets a nested hash <code>params[:person]</code> with
the person attributes set in the form. That hash is ready to be passed to
<code>Person.create</code>:</p>

<pre>if @person = Person.create(params[:person])
  # success
else
  # error handling
end</pre>

<p>Interestingly, the exact same view code in the previous example can be used
to edit a person. If <code>@person</code> is an existing record with name
“John Smith” and ID 256, the code above as is would yield instead:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">form</span> <span class="ruby-identifier">action</span>=<span class="ruby-string">&quot;/people/256&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;edit_person&quot;</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;edit_person_256&quot;</span> <span class="ruby-identifier">method</span>=<span class="ruby-string">&quot;post&quot;</span><span class="ruby-operator">&gt;</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">div</span> <span class="ruby-identifier">style</span>=<span class="ruby-string">&quot;margin:0;padding:0;display:inline&quot;</span><span class="ruby-operator">&gt;</span>
    <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;_method&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;hidden&quot;</span> <span class="ruby-identifier">value</span>=<span class="ruby-string">&quot;patch&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span>
    <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;authenticity_token&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;hidden&quot;</span> <span class="ruby-identifier">value</span>=<span class="ruby-string">&quot;NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-regexp">/div&gt;
  &lt;label for=&quot;person_first_name&quot;&gt;First name&lt;/</span><span class="ruby-identifier">label</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">:</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_first_name&quot;</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;person[first_name]&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;text&quot;</span> <span class="ruby-identifier">value</span>=<span class="ruby-string">&quot;John&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">&lt;</span><span class="ruby-identifier">br</span> <span class="ruby-regexp">/&gt;

  &lt;label for=&quot;person_last_name&quot;&gt;Last name&lt;/</span><span class="ruby-identifier">label</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">:</span>
  <span class="ruby-operator">&lt;</span><span class="ruby-identifier">input</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_last_name&quot;</span> <span class="ruby-identifier">name</span>=<span class="ruby-string">&quot;person[last_name]&quot;</span> <span class="ruby-identifier">type</span>=<span class="ruby-string">&quot;text&quot;</span> <span class="ruby-identifier">value</span>=<span class="ruby-string">&quot;Smith&quot;</span> <span class="ruby-operator">/</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">&lt;</span><span class="ruby-identifier">br</span> <span class="ruby-regexp">/&gt;

  &lt;input name=&quot;commit&quot; type=&quot;submit&quot; value=&quot;Update Person&quot; /</span><span class="ruby-operator">&gt;</span>
<span class="ruby-operator">&lt;</span><span class="ruby-regexp">/form&gt;
</span></pre>

<p>Note that the endpoint, default values, and submit button label are
tailored for <code>@person</code>. That works that way because the involved
helpers know whether the resource is a new record or not, and generate <a
href="../../HTML.html">HTML</a> accordingly.</p>

<p>The controller would receive the form data again in
<code>params[:person]</code>, ready to be passed to
<code>Person#update</code>:</p>

<pre>if @person.update(params[:person])
  # success
else
  # error handling
end</pre>

<p>That’s how you typically work with resources.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-check_box">check_box</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-color_field">color_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-date_field">date_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-datetime_field">datetime_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-datetime_local_field">datetime_local_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-email_field">email_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-fields_for">fields_for</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-file_field">file_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-form_for">form_for</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>H</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-hidden_field">hidden_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-label">label</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>M</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-month_field">month_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-number_field">number_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-password_field">password_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-phone_field">phone_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-radio_button">radio_button</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-range_field">range_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-search_field">search_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-telephone_field">telephone_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-text_area">text_area</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-text_field">text_field</a>,
              </li>
            
              
              <li>
                <a href="FormHelper.html#method-i-time_field">time_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-url_field">url_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>W</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormHelper.html#method-i-week_field">week_field</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="FormTagHelper.html">
              ActionView::Helpers::FormTagHelper
            </a>
          
        </li>
      
        <li>
          
            <a href="UrlHelper.html">
              ActionView::Helpers::UrlHelper
            </a>
          
        </li>
      
        <li>
          
            <a href="../ModelNaming.html">
              ActionView::ModelNaming
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-check_box">
            
              <b>check_box</b>(object_name, method, options = {}, checked_value = &quot;1&quot;, unchecked_value = &quot;0&quot;)
            
            <a href="FormHelper.html#method-i-check_box" name="method-i-check_box" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a checkbox tag tailored for accessing a specified attribute
(identified by <code>method</code>) on an object assigned to the template
(identified by <code>object</code>). This object must be an instance object
(@object) and not a local object. It’s intended that <code>method</code>
returns an integer and if that integer is above zero, then the checkbox is
checked. Additional options on the input tag can be passed as a hash with
<code>options</code>. The <code>checked_value</code> defaults to 1 while
the default <code>unchecked_value</code> is set to 0 which is convenient
for boolean values.</p>

<h4 id="method-i-check_box-label-Gotcha">Gotcha</h4>

<p>The <a href="../../HTML.html">HTML</a> specification says unchecked check
boxes are not successful, and thus web browsers do not send them.
Unfortunately this introduces a gotcha: if an <code>Invoice</code> model
has a <code>paid</code> flag, and in the form that edits a paid invoice the
user unchecks its check box, no <code>paid</code> parameter is sent. So,
any mass-assignment idiom like</p>

<pre>@invoice.update(params[:invoice])</pre>

<p>wouldn’t update the flag.</p>

<p>To prevent this the helper generates an auxiliary hidden field before the
very check box. The hidden field has the same name and its attributes mimic
an unchecked check box.</p>

<p>This way, the client either sends only the hidden field (representing the
check box is unchecked), or both fields. Since the <a
href="../../HTML.html">HTML</a> specification says key/value pairs have to
be sent in the same order they appear in the form, and parameters
extraction gets the last occurrence of any repeated key in the query
string, that works for ordinary forms.</p>

<p>Unfortunately that workaround does not work when the check box goes within
an array-like parameter, as in</p>

<pre>&lt;%= fields_for &quot;project[invoice_attributes][]&quot;, invoice, index: nil do |form| %&gt;
  &lt;%= form.check_box :paid %&gt;
  ...
&lt;% end %&gt;</pre>

<p>because parameter name repetition is precisely what <a
href="../../Rails.html">Rails</a> seeks to distinguish the elements of the
array. For each item with a checked check box you get an extra ghost item
with only that attribute, assigned to “0”.</p>

<p>In that case it is preferable to either use <code>check_box_tag</code> or
to use hashes instead of arrays.</p>

<pre class="ruby"><span class="ruby-comment"># Let's say that @post.validated? is 1:</span>
<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;validated&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;post[validated]&quot; type=&quot;hidden&quot; value=&quot;0&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input checked=&quot;checked&quot; type=&quot;checkbox&quot; id=&quot;post_validated&quot; name=&quot;post[validated]&quot; value=&quot;1&quot; /&gt;</span>

<span class="ruby-comment"># Let's say that @puppy.gooddog is &quot;no&quot;:</span>
<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;puppy&quot;</span>, <span class="ruby-string">&quot;gooddog&quot;</span>, {}, <span class="ruby-string">&quot;yes&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;puppy[gooddog]&quot; type=&quot;hidden&quot; value=&quot;no&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;checkbox&quot; id=&quot;puppy_gooddog&quot; name=&quot;puppy[gooddog]&quot; value=&quot;yes&quot; /&gt;</span>

<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;eula&quot;</span>, <span class="ruby-string">&quot;accepted&quot;</span>, { <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'eula_check'</span> }, <span class="ruby-string">&quot;yes&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;eula[accepted]&quot; type=&quot;hidden&quot; value=&quot;no&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;checkbox&quot; class=&quot;eula_check&quot; id=&quot;eula_accepted&quot; name=&quot;eula[accepted]&quot; value=&quot;yes&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-check_box_source')" id="l_method-i-check_box_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L929" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-check_box_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 929</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">check_box</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">checked_value</span> = <span class="ruby-string">&quot;1&quot;</span>, <span class="ruby-identifier">unchecked_value</span> = <span class="ruby-string">&quot;0&quot;</span>)
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">CheckBox</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">checked_value</span>, <span class="ruby-identifier">unchecked_value</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-color_field">
            
              <b>color_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-color_field" name="method-i-color_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “color”.</p>

<pre class="ruby"><span class="ruby-identifier">color_field</span>(<span class="ruby-string">&quot;car&quot;</span>, <span class="ruby-string">&quot;color&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;car_color&quot; name=&quot;car[color]&quot; type=&quot;color&quot; value=&quot;#000000&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-color_field_source')" id="l_method-i-color_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L958" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-color_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 958</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">color_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">ColorField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-date_field">
            
              <b>date_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-date_field" name="method-i-date_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “date”.</p>

<pre class="ruby"><span class="ruby-identifier">date_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;date&quot; /&gt;</span>
</pre>

<p>The default value is generated by trying to call “to_date” on the object’s
value, which makes it behave as expected for instances of <a
href="../../DateTime.html">DateTime</a> and <a
href="../../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>.
You can still override that by passing the “value” option explicitly, e.g.</p>

<pre class="ruby"><span class="ruby-ivar">@user</span>.<span class="ruby-identifier">born_on</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1984</span>, <span class="ruby-value">1</span>, <span class="ruby-value">27</span>)
<span class="ruby-identifier">date_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;1984-05-12&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;date&quot; value=&quot;1984-05-12&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-date_field_source')" id="l_method-i-date_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1010" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-date_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1010</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">date_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">DateField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-datetime_field">
            
              <b>datetime_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-datetime_field" name="method-i-datetime_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “datetime”.</p>

<pre class="ruby"><span class="ruby-identifier">datetime_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;datetime&quot; /&gt;</span>
</pre>

<p>The default value is generated by trying to call <code>strftime</code> with
“%Y-%m-%dT%T.%L%z” on the object’s value, which makes it behave as expected
for instances of <a href="../../DateTime.html">DateTime</a> and <a
href="../../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>.</p>

<pre class="ruby"><span class="ruby-ivar">@user</span>.<span class="ruby-identifier">born_on</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1984</span>, <span class="ruby-value">1</span>, <span class="ruby-value">12</span>)
<span class="ruby-identifier">datetime_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;datetime&quot; value=&quot;1984-01-12T00:00:00.000+0000&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-datetime_field_source')" id="l_method-i-datetime_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1044" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-datetime_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1044</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">datetime_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">DatetimeField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-datetime_local_field">
            
              <b>datetime_local_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-datetime_local_field" name="method-i-datetime_local_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “datetime-local”.</p>

<pre class="ruby"><span class="ruby-identifier">datetime_local_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;datetime-local&quot; /&gt;</span>
</pre>

<p>The default value is generated by trying to call <code>strftime</code> with
“%Y-%m-%dT%T” on the object’s value, which makes it behave as expected for
instances of <a href="../../DateTime.html">DateTime</a> and <a
href="../../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>.</p>

<pre class="ruby"><span class="ruby-ivar">@user</span>.<span class="ruby-identifier">born_on</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1984</span>, <span class="ruby-value">1</span>, <span class="ruby-value">12</span>)
<span class="ruby-identifier">datetime_local_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;datetime-local&quot; value=&quot;1984-01-12T00:00:00&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-datetime_local_field_source')" id="l_method-i-datetime_local_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1061" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-datetime_local_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1061</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">datetime_local_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">DatetimeLocalField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-email_field">
            
              <b>email_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-email_field" name="method-i-email_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “email”.</p>

<pre class="ruby"><span class="ruby-identifier">email_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;address&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_address&quot; name=&quot;user[address]&quot; type=&quot;email&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-email_field_source')" id="l_method-i-email_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1113" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-email_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1113</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">email_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">EmailField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-fields_for">
            
              <b>fields_for</b>(record_name, record_object = nil, options = {}, &amp;block)
            
            <a href="FormHelper.html#method-i-fields_for" name="method-i-fields_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a scope around a specific model object like <a
href="FormHelper.html#method-i-form_for">#form_for</a>, but doesn’t create
the form tags themselves. This makes <a
href="FormHelper.html#method-i-fields_for">#fields_for</a> suitable for
specifying additional model objects in the same form.</p>

<p>Although the usage and purpose of <code>field_for</code> is similar to
<code>form_for</code>‘s, its method signature is slightly different. Like
<code>form_for</code>, it yields a <a
href="FormBuilder.html">FormBuilder</a> object associated with a particular
model object to a block, and within the block allows methods to be called
on the builder to generate fields associated with the model object. Fields
may reflect a model object in two ways - how they are named (hence how
submitted values appear within the <code>params</code> hash in the
controller) and what default values are shown when the form the fields
appear in is first displayed. In order for both of these features to be
specified independently, both an object name (represented by either a
symbol or string) and the object itself can be passed to the method
separately -</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  First name: &lt;%= person_form.text_field :first_name %&gt;
  Last name : &lt;%= person_form.text_field :last_name %&gt;

  &lt;%= fields_for :permission, @person.permission do |permission_fields| %&gt;
    Admin?  : &lt;%= permission_fields.check_box :admin %&gt;
  &lt;% end %&gt;

  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>In this case, the checkbox field will be represented by an <a
href="../../HTML.html">HTML</a> <code>input</code> tag with the
<code>name</code> attribute <code>permission[admin]</code>, and the
submitted value will appear in the controller as
<code>params[:permission][:admin]</code>. If
<code>@person.permission</code> is an existing record with an attribute
<code>admin</code>, the initial state of the checkbox when first displayed
will reflect the value of <code>@person.permission.admin</code>.</p>

<p>Often this can be simplified by passing just the name of the model object
to <code>fields_for</code> -</p>

<pre>&lt;%= fields_for :permission do |permission_fields| %&gt;
  Admin?: &lt;%= permission_fields.check_box :admin %&gt;
&lt;% end %&gt;</pre>

<p>…in which case, if <code>:permission</code> also happens to be the name of
an instance variable <code>@permission</code>, the initial state of the
input field will reflect the value of that variable’s attribute
<code>@permission.admin</code>.</p>

<p>Alternatively, you can pass just the model object itself (if the first
argument isn’t a string or symbol <code>fields_for</code> will realize that
the name has been omitted) -</p>

<pre>&lt;%= fields_for @person.permission do |permission_fields| %&gt;
  Admin?: &lt;%= permission_fields.check_box :admin %&gt;
&lt;% end %&gt;</pre>

<p>and <code>fields_for</code> will derive the required name of the field from
the <em>class</em> of the model object, e.g. if
<code>@person.permission</code>, is of class <code>Permission</code>, the
field will still be named <code>permission[admin]</code>.</p>

<p>Note: This also works for the methods in FormOptionHelper and <a
href="DateHelper.html">DateHelper</a> that are designed to work with an
object as base, like FormOptionHelper#collection_select and <a
href="DateHelper.html#method-i-datetime_select">ActionView::Helpers::DateHelper#datetime_select</a>.</p>

<h3 id="method-i-fields_for-label-Nested+Attributes+Examples">Nested Attributes Examples</h3>

<p>When the object belonging to the current scope has a nested attribute
writer for a certain attribute, <a
href="FormHelper.html#method-i-fields_for">#fields_for</a> will yield a new
scope for that attribute. This allows you to create forms that set or
change the attributes of a parent object and its associations in one go.</p>

<p>Nested attribute writers are normal setter methods named after an
association. The most common way of defining these writers is either with
<code>accepts_nested_attributes_for</code> in a model definition or by
defining a method with the proper name. For example: the attribute writer
for the association <code>:address</code> is called
<code>address_attributes=</code>.</p>

<p>Whether a one-to-one or one-to-many style form builder will be yielded
depends on whether the normal reader method returns a <em>single</em>
object or an <em>array</em> of objects.</p>

<h4 id="method-i-fields_for-label-One-to-one">One-to-one</h4>

<p>Consider a Person class which returns a <em>single</em> Address from the
<code>address</code> reader method and responds to the
<code>address_attributes=</code> writer method:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">address</span>
    <span class="ruby-ivar">@address</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier">address_attributes=</span>(<span class="ruby-identifier">attributes</span>)
    <span class="ruby-comment"># Process the attributes hash</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This model can now be used with a nested <a
href="FormHelper.html#method-i-fields_for">#fields_for</a>, like so:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :address do |address_fields| %&gt;
    Street  : &lt;%= address_fields.text_field :street %&gt;
    Zip code: &lt;%= address_fields.text_field :zip_code %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>When address is already an association on a Person you can use
<code>accepts_nested_attributes_for</code> to define the writer method for
you:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_one</span> :<span class="ruby-identifier">address</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">address</span>
<span class="ruby-keyword">end</span>
</pre>

<p>If you want to destroy the associated model through the form, you have to
enable it first using the <code>:allow_destroy</code> option for
<code>accepts_nested_attributes_for</code>:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_one</span> :<span class="ruby-identifier">address</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">address</span>, <span class="ruby-identifier">allow_destroy</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Now, when you use a form element with the <code>_destroy</code> parameter,
with a value that evaluates to <code>true</code>, you will destroy the
associated model (eg. 1, ‘1’, true, or ‘true’):</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :address do |address_fields| %&gt;
    ...
    Delete: &lt;%= address_fields.check_box :_destroy %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<h4 id="method-i-fields_for-label-One-to-many">One-to-many</h4>

<p>Consider a Person class which returns an <em>array</em> of Project
instances from the <code>projects</code> reader method and responds to the
<code>projects_attributes=</code> writer method:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">projects</span>
    [<span class="ruby-ivar">@project1</span>, <span class="ruby-ivar">@project2</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier">projects_attributes=</span>(<span class="ruby-identifier">attributes</span>)
    <span class="ruby-comment"># Process the attributes hash</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Note that the <code>projects_attributes=</code> writer method is in fact
required for <a href="FormHelper.html#method-i-fields_for">#fields_for</a>
to correctly identify <code>:projects</code> as a collection, and the
correct indices to be set in the form markup.</p>

<p>When projects is already an association on Person you can use
<code>accepts_nested_attributes_for</code> to define the writer method for
you:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_many</span> :<span class="ruby-identifier">projects</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">projects</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This model can now be used with a nested fields_for. The block given to the
nested <a href="FormHelper.html#method-i-fields_for">#fields_for</a> call
will be repeated for each instance in the collection:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    &lt;% if project_fields.object.active? %&gt;
      Name: &lt;%= project_fields.text_field :name %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>It’s also possible to specify the instance to be used:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;% @person.projects.each do |project| %&gt;
    &lt;% if project.active? %&gt;
      &lt;%= person_form.fields_for :projects, project do |project_fields| %&gt;
        Name: &lt;%= project_fields.text_field :name %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>Or a collection to be used:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects, @active_projects do |project_fields| %&gt;
    Name: &lt;%= project_fields.text_field :name %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>If you want to destroy any of the associated models through the form, you
have to enable it first using the <code>:allow_destroy</code> option for
<code>accepts_nested_attributes_for</code>:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_many</span> :<span class="ruby-identifier">projects</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">projects</span>, <span class="ruby-identifier">allow_destroy</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This will allow you to specify which models to destroy in the attributes
hash by adding a form element for the <code>_destroy</code> parameter with
a value that evaluates to <code>true</code> (eg. 1, ‘1’, true, or ‘true’):</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    Delete: &lt;%= project_fields.check_box :_destroy %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>When a collection is used you might want to know the index of each object
into the array. For this purpose, the <code>index</code> method is
available in the <a href="FormBuilder.html">FormBuilder</a> object.</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    Project #&lt;%= project_fields.index %&gt;
    ...
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>Note that <a href="FormHelper.html#method-i-fields_for">#fields_for</a>
will automatically generate a hidden field to store the ID of the record.
There are circumstances where this hidden field is not needed and you can
pass <code>hidden_field_id: false</code> to prevent <a
href="FormHelper.html#method-i-fields_for">#fields_for</a> from rendering
it automatically.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-fields_for_source')" id="l_method-i-fields_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L697" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-fields_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 697</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">fields_for</span>(<span class="ruby-identifier">record_name</span>, <span class="ruby-identifier">record_object</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">builder</span> = <span class="ruby-identifier">instantiate_builder</span>(<span class="ruby-identifier">record_name</span>, <span class="ruby-identifier">record_object</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">capture</span>(<span class="ruby-identifier">builder</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-file_field">
            
              <b>file_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-file_field" name="method-i-file_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a file upload input tag tailored for accessing a specified
attribute (identified by <code>method</code>) on an object assigned to the
template (identified by <code>object</code>). Additional options on the
input tag can be passed as a hash with <code>options</code>. These options
will be tagged onto the <a href="../../HTML.html">HTML</a> as an <a
href="../../HTML.html">HTML</a> element attribute as in the example shown.</p>

<p>Using this method inside a <code>form_for</code> block will set the
enclosing form’s encoding to <code>multipart/form-data</code>.</p>

<h4 id="method-i-file_field-label-Options">Options</h4>
<ul><li>
<p>Creates standard <a href="../../HTML.html">HTML</a> attributes for the tag.</p>
</li><li>
<p><code>:disabled</code> - If set to true, the user will not be able to use
this input.</p>
</li><li>
<p><code>:multiple</code> - If set to true, *in most updated browsers* the
user will be allowed to select multiple files.</p>
</li><li>
<p><code>:accept</code> - If set to one or multiple mime-types, the user will
be suggested a filter when choosing a file. You still need to set up model
validations.</p>
</li></ul>

<h4 id="method-i-file_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">avatar</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;user_avatar&quot; name=&quot;user[avatar]&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">image</span>, :<span class="ruby-identifier">multiple</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;post_image&quot; name=&quot;post[image]&quot; multiple=&quot;true&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">attached</span>, <span class="ruby-identifier">accept</span><span class="ruby-operator">:</span> <span class="ruby-string">'text/html'</span>)
<span class="ruby-comment"># =&gt; &lt;input accept=&quot;text/html&quot; type=&quot;file&quot; id=&quot;post_attached&quot; name=&quot;post[attached]&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">image</span>, <span class="ruby-identifier">accept</span><span class="ruby-operator">:</span> <span class="ruby-string">'image/png,image/gif,image/jpeg'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;post_image&quot; name=&quot;post[image]&quot; accept=&quot;image/png,image/gif,image/jpeg&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">attachment</span>, :<span class="ruby-identifier">file</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'file_input'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;attachment_file&quot; name=&quot;attachment[file]&quot; class=&quot;file_input&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-file_field_source')" id="l_method-i-file_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L841" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-file_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 841</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">file_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">FileField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-form_for">
            
              <b>form_for</b>(record, options = {}, &amp;block)
            
            <a href="FormHelper.html#method-i-form_for" name="method-i-form_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a form that allows the user to create or update the attributes of a
specific model object.</p>

<p>The method can be used in several slightly different ways, depending on how
much you wish to rely on <a href="../../Rails.html">Rails</a> to infer
automatically from the model how the form should be constructed. For a
generic model object, a form can be created by passing
<code>form_for</code> a string or symbol representing the object we are
concerned with:</p>

<pre>&lt;%= form_for :person do |f| %&gt;
  First name: &lt;%= f.text_field :first_name %&gt;&lt;br /&gt;
  Last name : &lt;%= f.text_field :last_name %&gt;&lt;br /&gt;
  Biography : &lt;%= f.text_area :biography %&gt;&lt;br /&gt;
  Admin?    : &lt;%= f.check_box :admin %&gt;&lt;br /&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>The variable <code>f</code> yielded to the block is a <a
href="FormBuilder.html">FormBuilder</a> object that incorporates the
knowledge about the model object represented by <code>:person</code> passed
to <code>form_for</code>. Methods defined on the <a
href="FormBuilder.html">FormBuilder</a> are used to generate fields bound
to this model. Thus, for example,</p>

<pre>&lt;%= f.text_field :first_name %&gt;</pre>

<p>will get expanded to</p>

<pre>&lt;%= text_field :person, :first_name %&gt;</pre>

<p>which results in an html <code>&lt;input&gt;</code> tag whose
<code>name</code> attribute is <code>person[first_name]</code>. This means
that when the form is submitted, the value entered by the user will be
available in the controller as <code>params[:person][:first_name]</code>.</p>

<p>For fields generated in this way using the <a
href="FormBuilder.html">FormBuilder</a>, if <code>:person</code> also
happens to be the name of an instance variable <code>@person</code>, the
default value of the field shown when the form is initially displayed (e.g.
in the situation where you are editing an existing record) will be the
value of the corresponding attribute of <code>@person</code>.</p>

<p>The rightmost argument to <code>form_for</code> is an optional hash of
options -</p>
<ul><li>
<p><code>:url</code> - The URL the form is to be submitted to. This may be
represented in the same way as values passed to <code>url_for</code> or
<code>link_to</code>. So for example you may use a named route directly.
When the model is represented by a string or symbol, as in the example
above, if the <code>:url</code> option is not specified, by default the
form will be sent back to the current url (We will describe below an
alternative resource-oriented usage of <code>form_for</code> in which the
URL does not need to be specified explicitly).</p>
</li><li>
<p><code>:namespace</code> - A namespace for your form to ensure uniqueness of
id attributes on form elements. The namespace attribute will be prefixed
with underscore on the generated <a href="../../HTML.html">HTML</a> id.</p>
</li><li>
<p><code>:html</code> - Optional <a href="../../HTML.html">HTML</a> attributes
for the form tag.</p>
</li></ul>

<p>Also note that <code>form_for</code> doesn’t create an exclusive scope.
It’s still possible to use both the stand-alone <a
href="FormHelper.html">FormHelper</a> methods and methods from <a
href="FormTagHelper.html">FormTagHelper</a>. For example:</p>

<pre>&lt;%= form_for :person do |f| %&gt;
  First name: &lt;%= f.text_field :first_name %&gt;
  Last name : &lt;%= f.text_field :last_name %&gt;
  Biography : &lt;%= text_area :person, :biography %&gt;
  Admin?    : &lt;%= check_box_tag &quot;person[admin]&quot;, &quot;1&quot;, @person.company.admin? %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>This also works for the methods in FormOptionHelper and <a
href="DateHelper.html">DateHelper</a> that are designed to work with an
object as base, like FormOptionHelper#collection_select and <a
href="DateHelper.html#method-i-datetime_select">ActionView::Helpers::DateHelper#datetime_select</a>.</p>

<h3 id="method-i-form_for-label-%23form_for+with+a+model+object"><a href="FormHelper.html#method-i-form_for">form_for</a> with a model object</h3>

<p>In the examples above, the object to be created or edited was represented
by a symbol passed to <code>form_for</code>, and we noted that a string can
also be used equivalently. It is also possible, however, to pass a model
object itself to <code>form_for</code>. For example, if <code>@post</code>
is an existing record you wish to edit, you can create the form using</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>This behaves in almost the same way as outlined previously, with a couple
of small exceptions. First, the prefix used to name the input elements
within the form (hence the key that denotes them in the <code>params</code>
hash) is actually derived from the object’s <em>class</em>, e.g.
<code>params[:post]</code> if the object’s class is <code>Post</code>.
However, this can be overwritten using the <code>:as</code> option, e.g. -</p>

<pre>&lt;%= form_for(@person, as: :client) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>would result in <code>params[:client]</code>.</p>

<p>Secondly, the field values shown when the form is initially displayed are
taken from the attributes of the object passed to <code>form_for</code>,
regardless of whether the object is an instance variable. So, for example,
if we had a <em>local</em> variable <code>post</code> representing an
existing record,</p>

<pre>&lt;%= form_for post do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>would produce a form with fields whose initial state reflect the current
values of the attributes of <code>post</code>.</p>

<h3 id="method-i-form_for-label-Resource-oriented+style">Resource-oriented style</h3>

<p>In the examples just shown, although not indicated explicitly, we still
need to use the <code>:url</code> option in order to specify where the form
is going to be sent. However, further simplification is possible if the
record passed to <code>form_for</code> is a <em>resource</em>, i.e. it
corresponds to a set of RESTful routes, e.g. defined using the
<code>resources</code> method in <code>config/routes.rb</code>. In this
case <a href="../../Rails.html">Rails</a> will simply infer the appropriate
URL from the record itself. For example,</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>is then equivalent to something like:</p>

<pre>&lt;%= form_for @post, as: :post, url: post_path(@post), method: :patch, html: { class: &quot;edit_post&quot;, id: &quot;edit_post_45&quot; } do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>And for a new record</p>

<pre>&lt;%= form_for(Post.new) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>is equivalent to something like:</p>

<pre>&lt;%= form_for @post, as: :post, url: posts_path, html: { class: &quot;new_post&quot;, id: &quot;new_post&quot; } do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>However you can still overwrite individual conventions, such as:</p>

<pre>&lt;%= form_for(@post, url: super_posts_path) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>You can also set the answer format, like this:</p>

<pre>&lt;%= form_for(@post, format: :json) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>For namespaced routes, like <code>admin_post_url</code>:</p>

<pre>&lt;%= form_for([:admin, @post]) do |f| %&gt;
 ...
&lt;% end %&gt;</pre>

<p>If your resource has associations defined, for example, you want to add
comments to the document given that the routes are set correctly:</p>

<pre>&lt;%= form_for([@document, @comment]) do |f| %&gt;
 ...
&lt;% end %&gt;</pre>

<p>Where <code>@document = Document.find(params[:id])</code> and
<code>@comment = Comment.new</code>.</p>

<h3 id="method-i-form_for-label-Setting+the+method">Setting the method</h3>

<p>You can force the form to use the full array of HTTP verbs by setting</p>

<pre>method: (:get|:post|:patch|:put|:delete)</pre>

<p>in the options hash. If the verb is not GET or POST, which are natively
supported by <a href="../../HTML.html">HTML</a> forms, the form will be set
to POST and a hidden input called _method will carry the intended verb for
the server to interpret.</p>

<h3 id="method-i-form_for-label-Unobtrusive+JavaScript">Unobtrusive JavaScript</h3>

<p>Specifying:</p>

<pre>remote: true</pre>

<p>in the options hash creates a form that will allow the unobtrusive
JavaScript drivers to modify its behavior. The expected default behavior is
an XMLHttpRequest in the background instead of the regular POST
arrangement, but ultimately the behavior is the choice of the JavaScript
driver implementor. Even though it’s using JavaScript to serialize the form
elements, the form submission will work just like a regular submission as
viewed by the receiving side (all elements available in
<code>params</code>).</p>

<p>Example:</p>

<pre>&lt;%= form_for(@post, remote: true) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>The <a href="../../HTML.html">HTML</a> generated for this would be:</p>

<pre>&lt;form action='http://www.example.com' method='post' data-remote='true'&gt;
  &lt;div style='margin:0;padding:0;display:inline'&gt;
    &lt;input name='_method' type='hidden' value='patch' /&gt;
  &lt;/div&gt;
  ...
&lt;/form&gt;</pre>

<h3 id="method-i-form_for-label-Setting+HTML+options">Setting <a href="../../HTML.html">HTML</a> options</h3>

<p>You can set data attributes directly by passing in a data hash, but all
other <a href="../../HTML.html">HTML</a> options must be wrapped in the <a
href="../../HTML.html">HTML</a> key. Example:</p>

<pre>&lt;%= form_for(@post, data: { behavior: &quot;autosave&quot; }, html: { name: &quot;go&quot; }) do |f| %&gt;
  ...
&lt;% end %&gt;</pre>

<p>The <a href="../../HTML.html">HTML</a> generated for this would be:</p>

<pre>&lt;form action='http://www.example.com' method='post' data-behavior='autosave' name='go'&gt;
  &lt;div style='margin:0;padding:0;display:inline'&gt;
    &lt;input name='_method' type='hidden' value='patch' /&gt;
  &lt;/div&gt;
  ...
&lt;/form&gt;</pre>

<h3 id="method-i-form_for-label-Removing+hidden+model+id%27s">Removing hidden model id’s</h3>

<p>The <a href="FormHelper.html#method-i-form_for">#form_for</a> method
automatically includes the model id as a hidden field in the form. This is
used to maintain the correlation between the form data and its associated
model. Some ORM systems do not use IDs on nested models so in this case you
want to be able to disable the hidden id.</p>

<p>In the following example the Post model has many Comments stored within it
in a NoSQL database, thus there is no primary key for comments.</p>

<p>Example:</p>

<pre>&lt;%= form_for(@post) do |f| %&gt;
  &lt;%= f.fields_for(:comments, include_id: false) do |cf| %&gt;
    ...
  &lt;% end %&gt;
&lt;% end %&gt;</pre>

<h3 id="method-i-form_for-label-Customized+form+builders">Customized form builders</h3>

<p>You can also build forms using a customized <a
href="FormBuilder.html">FormBuilder</a> class. Subclass <a
href="FormBuilder.html">FormBuilder</a> and override or define some more
helpers, then use your custom builder. For example, let’s say you made a
helper to automatically add labels to form inputs.</p>

<pre>&lt;%= form_for @person, url: { action: &quot;create&quot; }, builder: LabellingFormBuilder do |f| %&gt;
  &lt;%= f.text_field :first_name %&gt;
  &lt;%= f.text_field :last_name %&gt;
  &lt;%= f.text_area :biography %&gt;
  &lt;%= f.check_box :admin %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>In this case, if you use this:</p>

<pre>&lt;%= render f %&gt;</pre>

<p>The rendered template is <code>people/_labelling_form</code> and the local
variable referencing the form builder is called
<code>labelling_form</code>.</p>

<p>The custom <a href="FormBuilder.html">FormBuilder</a> class is
automatically merged with the options of a nested <a
href="FormHelper.html#method-i-fields_for">#fields_for</a> call, unless
it’s explicitly set.</p>

<p>In many cases you will want to wrap the above in another helper, so you
could do something like the following:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">labelled_form_for</span>(<span class="ruby-identifier">record_or_name_or_array</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">options</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
  <span class="ruby-identifier">form_for</span>(<span class="ruby-identifier">record_or_name_or_array</span>, *(<span class="ruby-identifier">args</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">builder</span><span class="ruby-operator">:</span> <span class="ruby-constant">LabellingFormBuilder</span>)), &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span>
</pre>

<p>If you don’t need to attach a form to a model instance, then check out <a
href="FormTagHelper.html#method-i-form_tag">ActionView::Helpers::FormTagHelper#form_tag</a>.</p>

<h3 id="method-i-form_for-label-Form+to+external+resources">Form to external resources</h3>

<p>When you build forms to external resources sometimes you need to set an
authenticity token or just render a form without it, for example when you
submit data to a payment gateway number and types of fields could be
limited.</p>

<p>To set an authenticity token you need to pass an
<code>:authenticity_token</code> parameter</p>

<pre>&lt;%= form_for @invoice, url: external_url, authenticity_token: 'external_token' do |f|
  ...
&lt;% end %&gt;</pre>

<p>If you don’t want to an authenticity token field be rendered at all just
pass <code>false</code>:</p>

<pre>&lt;%= form_for @invoice, url: external_url, authenticity_token: false do |f|
  ...
&lt;% end %&gt;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-form_for_source')" id="l_method-i-form_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L414" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-form_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 414</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">form_for</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;Missing block&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
  <span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:html</span>] <span class="ruby-operator">||=</span> {}

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">record</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Symbol</span>
    <span class="ruby-identifier">object_name</span> = <span class="ruby-identifier">record</span>
    <span class="ruby-identifier">object</span>      = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">object</span>      = <span class="ruby-identifier">record</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">last</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">record</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;First argument in form cannot contain nil or be empty&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">object</span>
    <span class="ruby-identifier">object_name</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:as</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">model_name_from_record_or_class</span>(<span class="ruby-identifier">object</span>).<span class="ruby-identifier">param_key</span>
    <span class="ruby-identifier">apply_form_for_options!</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:data</span>]   = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:data</span>)   <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value">:data</span>)
  <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:remote</span>] = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:remote</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value">:remote</span>)
  <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:method</span>] = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:method</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value">:method</span>)
  <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:authenticity_token</span>] = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:authenticity_token</span>)

  <span class="ruby-identifier">builder</span> = <span class="ruby-identifier">instantiate_builder</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">options</span>)
  <span class="ruby-identifier">output</span>  = <span class="ruby-identifier">capture</span>(<span class="ruby-identifier">builder</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:multipart</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">builder</span>.<span class="ruby-identifier">multipart?</span>

  <span class="ruby-identifier">form_tag</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:url</span>] <span class="ruby-operator">||</span> {}, <span class="ruby-identifier">html_options</span>) { <span class="ruby-identifier">output</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-hidden_field">
            
              <b>hidden_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-hidden_field" name="method-i-hidden_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a hidden input tag tailored for accessing a specified attribute
(identified by <code>method</code>) on an object assigned to the template
(identified by <code>object</code>). Additional options on the input tag
can be passed as a hash with <code>options</code>. These options will be
tagged onto the <a href="../../HTML.html">HTML</a> as an <a
href="../../HTML.html">HTML</a> element attribute as in the example shown.</p>

<h4 id="method-i-hidden_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">signup</span>, :<span class="ruby-identifier">pass_confirm</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;signup_pass_confirm&quot; name=&quot;signup[pass_confirm]&quot; value=&quot;#{@signup.pass_confirm}&quot; /&gt;</span>

<span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">tag_list</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;post_tag_list&quot; name=&quot;post[tag_list]&quot; value=&quot;#{@post.tag_list}&quot; /&gt;</span>

<span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">token</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;user_token&quot; name=&quot;user[token]&quot; value=&quot;#{@user.token}&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-hidden_field_source')" id="l_method-i-hidden_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L809" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-hidden_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 809</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">hidden_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">HiddenField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-label">
            
              <b>label</b>(object_name, method, content_or_options = nil, options = nil, &amp;block)
            
            <a href="FormHelper.html#method-i-label" name="method-i-label" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a label tag tailored for labelling an input field for a specified
attribute (identified by <code>method</code>) on an object assigned to the
template (identified by <code>object</code>). The text of label will
default to the attribute name unless a translation is found in the current
<a href="../../I18n.html">I18n</a> locale (through
helpers.label.&lt;modelname&gt;.&lt;attribute&gt;) or you specify it
explicitly. Additional options on the label tag can be passed as a hash
with <code>options</code>. These options will be tagged onto the <a
href="../../HTML.html">HTML</a> as an <a href="../../HTML.html">HTML</a>
element attribute as in the example shown, except for the
<code>:value</code> option, which is designed to target labels for <a
href="FormHelper.html#method-i-radio_button">#radio_button</a> tags (where
the value is used in the ID of the input tag).</p>

<h4 id="method-i-label-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot;&gt;Title&lt;/label&gt;</span>
</pre>

<p>You can localize your labels based on model and attribute names. For
example you can define the following in your locale (e.g. en.yml)</p>

<pre>helpers:
  label:
    post:
      body: &quot;Write your entire text here&quot;</pre>

<p>Which then will result in</p>

<pre class="ruby"><span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">body</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_body&quot;&gt;Write your entire text here&lt;/label&gt;</span>
</pre>

<p>Localization can also be based purely on the translation of the
attribute-name (if you are using <a
href="../../ActiveRecord.html">ActiveRecord</a>):</p>

<pre class="ruby"><span class="ruby-identifier">activerecord</span><span class="ruby-operator">:</span>
  <span class="ruby-identifier">attributes</span><span class="ruby-operator">:</span>
    <span class="ruby-identifier">post</span><span class="ruby-operator">:</span>
      <span class="ruby-identifier">cost</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Total cost&quot;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">cost</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_cost&quot;&gt;Total cost&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-string">&quot;A short title&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot;&gt;A short title&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-string">&quot;A short title&quot;</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;title_label&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot; class=&quot;title_label&quot;&gt;A short title&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">privacy</span>, <span class="ruby-string">&quot;Public Post&quot;</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;public&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_privacy_public&quot;&gt;Public Post&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">terms</span>) <span class="ruby-keyword">do</span>
  <span class="ruby-string">'Accept &lt;a href=&quot;/terms&quot;&gt;Terms&lt;/a&gt;.'</span>.<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-label_source')" id="l_method-i-label_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L749" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-label_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 749</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">label</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">content_or_options</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">Label</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">content_or_options</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>(&amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-month_field">
            
              <b>month_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-month_field" name="method-i-month_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “month”.</p>

<pre class="ruby"><span class="ruby-identifier">month_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;month&quot; /&gt;</span>
</pre>

<p>The default value is generated by trying to call <code>strftime</code> with
“%Y-%m” on the object’s value, which makes it behave as expected for
instances of <a href="../../DateTime.html">DateTime</a> and <a
href="../../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>.</p>

<pre class="ruby"><span class="ruby-ivar">@user</span>.<span class="ruby-identifier">born_on</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1984</span>, <span class="ruby-value">1</span>, <span class="ruby-value">27</span>)
<span class="ruby-identifier">month_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;date&quot; value=&quot;1984-01&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-month_field_source')" id="l_method-i-month_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1078" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-month_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1078</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">month_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">MonthField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-number_field">
            
              <b>number_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-number_field" name="method-i-number_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an input tag of type “number”.</p>

<h4 id="method-i-number_field-label-Options">Options</h4>
<ul><li>
<p>Accepts same options as number_field_tag</p>
</li></ul>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-number_field_source')" id="l_method-i-number_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1121" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-number_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1121</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">number_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">NumberField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-password_field">
            
              <b>password_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-password_field" name="method-i-password_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an input tag of the “password” type tailored for accessing a
specified attribute (identified by <code>method</code>) on an object
assigned to the template (identified by <code>object</code>). Additional
options on the input tag can be passed as a hash with <code>options</code>.
These options will be tagged onto the <a href="../../HTML.html">HTML</a> as
an <a href="../../HTML.html">HTML</a> element attribute as in the example
shown. For security reasons this field is blank by default; pass in a value
via <code>options</code> if this is not desired.</p>

<h4 id="method-i-password_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">password_field</span>(:<span class="ruby-identifier">login</span>, :<span class="ruby-identifier">pass</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-value">20</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;password&quot; id=&quot;login_pass&quot; name=&quot;login[pass]&quot; size=&quot;20&quot; /&gt;</span>

<span class="ruby-identifier">password_field</span>(:<span class="ruby-identifier">account</span>, :<span class="ruby-identifier">secret</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;form_input&quot;</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@account</span>.<span class="ruby-identifier">secret</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;password&quot; id=&quot;account_secret&quot; name=&quot;account[secret]&quot; value=&quot;#{@account.secret}&quot; class=&quot;form_input&quot; /&gt;</span>

<span class="ruby-identifier">password_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">password</span>, <span class="ruby-identifier">onchange</span><span class="ruby-operator">:</span> <span class="ruby-node">&quot;if ($('#user_password').val().length &gt; 30) { alert('Your password needs to be shorter!'); }&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;password&quot; id=&quot;user_password&quot; name=&quot;user[password]&quot; onchange=&quot;if ($('#user_password').val().length &gt; 30) { alert('Your password needs to be shorter!'); }&quot;/&gt;</span>

<span class="ruby-identifier">password_field</span>(:<span class="ruby-identifier">account</span>, :<span class="ruby-identifier">pin</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-value">20</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'form_input'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;password&quot; id=&quot;account_pin&quot; name=&quot;account[pin]&quot; size=&quot;20&quot; class=&quot;form_input&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-password_field_source')" id="l_method-i-password_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L791" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-password_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 791</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">password_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">PasswordField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-phone_field">
            
              <b>phone_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-phone_field" name="method-i-phone_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>aliases <a
href="FormHelper.html#method-i-telephone_field">#telephone_field</a></p>
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-radio_button">
            
              <b>radio_button</b>(object_name, method, tag_value, options = {})
            
            <a href="FormHelper.html#method-i-radio_button" name="method-i-radio_button" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a radio button tag for accessing a specified attribute (identified
by <code>method</code>) on an object assigned to the template (identified
by <code>object</code>). If the current value of <code>method</code> is
<code>tag_value</code> the radio button will be checked.</p>

<p>To force the radio button to be checked pass <code>checked: true</code> in
the <code>options</code> hash. You may pass <a
href="../../HTML.html">HTML</a> options there as well.</p>

<pre class="ruby"><span class="ruby-comment"># Let's say that @post.category returns &quot;rails&quot;:</span>
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;category&quot;</span>, <span class="ruby-string">&quot;rails&quot;</span>)
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;category&quot;</span>, <span class="ruby-string">&quot;java&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;radio&quot; id=&quot;post_category_rails&quot; name=&quot;post[category]&quot; value=&quot;rails&quot; checked=&quot;checked&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;radio&quot; id=&quot;post_category_java&quot; name=&quot;post[category]&quot; value=&quot;java&quot; /&gt;</span>

<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;receive_newsletter&quot;</span>, <span class="ruby-string">&quot;yes&quot;</span>)
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;receive_newsletter&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;radio&quot; id=&quot;user_receive_newsletter_yes&quot; name=&quot;user[receive_newsletter]&quot; value=&quot;yes&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;radio&quot; id=&quot;user_receive_newsletter_no&quot; name=&quot;user[receive_newsletter]&quot; value=&quot;no&quot; checked=&quot;checked&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-radio_button_source')" id="l_method-i-radio_button_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L950" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-radio_button_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 950</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">radio_button</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">RadioButton</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-range_field">
            
              <b>range_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-range_field" name="method-i-range_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an input tag of type “range”.</p>

<h4 id="method-i-range_field-label-Options">Options</h4>
<ul><li>
<p>Accepts same options as range_field_tag</p>
</li></ul>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-range_field_source')" id="l_method-i-range_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1129" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-range_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1129</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">range_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">RangeField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-search_field">
            
              <b>search_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-search_field" name="method-i-search_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an input of type “search” for accessing a specified attribute
(identified by <code>method</code>) on an object assigned to the template
(identified by <code>object_name</code>). Inputs of type “search” may be
styled differently by some browsers.</p>

<pre class="ruby"><span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_name&quot; name=&quot;user[name]&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">autosave</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>)
<span class="ruby-comment"># =&gt; &lt;input autosave=&quot;false&quot; id=&quot;user_name&quot; name=&quot;user[name]&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">results</span><span class="ruby-operator">:</span> <span class="ruby-value">3</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_name&quot; name=&quot;user[name]&quot; results=&quot;3&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-comment">#  Assume request.host returns &quot;www.example.com&quot;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">autosave</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input autosave=&quot;com.example.www&quot; id=&quot;user_name&quot; name=&quot;user[name]&quot; results=&quot;10&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">onsearch</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_name&quot; incremental=&quot;true&quot; name=&quot;user[name]&quot; onsearch=&quot;true&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">autosave</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>, <span class="ruby-identifier">onsearch</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input autosave=&quot;false&quot; id=&quot;user_name&quot; incremental=&quot;true&quot; name=&quot;user[name]&quot; onsearch=&quot;true&quot; type=&quot;search&quot; /&gt;</span>
<span class="ruby-identifier">search_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">name</span>, <span class="ruby-identifier">autosave</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">onsearch</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input autosave=&quot;com.example.www&quot; id=&quot;user_name&quot; incremental=&quot;true&quot; name=&quot;user[name]&quot; onsearch=&quot;true&quot; results=&quot;10&quot; type=&quot;search&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-search_field_source')" id="l_method-i-search_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L981" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-search_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 981</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">search_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">SearchField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-telephone_field">
            
              <b>telephone_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-telephone_field" name="method-i-telephone_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “tel”.</p>

<pre class="ruby"><span class="ruby-identifier">telephone_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;phone&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_phone&quot; name=&quot;user[phone]&quot; type=&quot;tel&quot; /&gt;</span>
</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="FormHelper.html#method-i-phone_field">phone_field</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-telephone_field_source')" id="l_method-i-telephone_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L990" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-telephone_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 990</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">telephone_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">TelField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-text_area">
            
              <b>text_area</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-text_area" name="method-i-text_area" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a textarea opening and closing tag set tailored for accessing a
specified attribute (identified by <code>method</code>) on an object
assigned to the template (identified by <code>object</code>). Additional
options on the input tag can be passed as a hash with <code>options</code>.</p>

<h4 id="method-i-text_area-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">text_area</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">body</span>, <span class="ruby-identifier">cols</span><span class="ruby-operator">:</span> <span class="ruby-value">20</span>, <span class="ruby-identifier">rows</span><span class="ruby-operator">:</span> <span class="ruby-value">40</span>)
<span class="ruby-comment"># =&gt; &lt;textarea cols=&quot;20&quot; rows=&quot;40&quot; id=&quot;post_body&quot; name=&quot;post[body]&quot;&gt;</span>
<span class="ruby-comment">#      #{@post.body}</span>
<span class="ruby-comment">#    &lt;/textarea&gt;</span>

<span class="ruby-identifier">text_area</span>(:<span class="ruby-identifier">comment</span>, :<span class="ruby-identifier">text</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;20x30&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;textarea cols=&quot;20&quot; rows=&quot;30&quot; id=&quot;comment_text&quot; name=&quot;comment[text]&quot;&gt;</span>
<span class="ruby-comment">#      #{@comment.text}</span>
<span class="ruby-comment">#    &lt;/textarea&gt;</span>

<span class="ruby-identifier">text_area</span>(:<span class="ruby-identifier">application</span>, :<span class="ruby-identifier">notes</span>, <span class="ruby-identifier">cols</span><span class="ruby-operator">:</span> <span class="ruby-value">40</span>, <span class="ruby-identifier">rows</span><span class="ruby-operator">:</span> <span class="ruby-value">15</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'app_input'</span>)
<span class="ruby-comment"># =&gt; &lt;textarea cols=&quot;40&quot; rows=&quot;15&quot; id=&quot;application_notes&quot; name=&quot;application[notes]&quot; class=&quot;app_input&quot;&gt;</span>
<span class="ruby-comment">#      #{@application.notes}</span>
<span class="ruby-comment">#    &lt;/textarea&gt;</span>

<span class="ruby-identifier">text_area</span>(:<span class="ruby-identifier">entry</span>, :<span class="ruby-identifier">body</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;20x20&quot;</span>, <span class="ruby-identifier">disabled</span><span class="ruby-operator">:</span> <span class="ruby-string">'disabled'</span>)
<span class="ruby-comment"># =&gt; &lt;textarea cols=&quot;20&quot; rows=&quot;20&quot; id=&quot;entry_body&quot; name=&quot;entry[body]&quot; disabled=&quot;disabled&quot;&gt;</span>
<span class="ruby-comment">#      #{@entry.body}</span>
<span class="ruby-comment">#    &lt;/textarea&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-text_area_source')" id="l_method-i-text_area_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L869" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-text_area_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 869</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">text_area</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">TextArea</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-text_field">
            
              <b>text_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-text_field" name="method-i-text_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an input tag of the “text” type tailored for accessing a specified
attribute (identified by <code>method</code>) on an object assigned to the
template (identified by <code>object</code>). Additional options on the
input tag can be passed as a hash with <code>options</code>. These options
will be tagged onto the <a href="../../HTML.html">HTML</a> as an <a
href="../../HTML.html">HTML</a> element attribute as in the example shown.</p>

<h4 id="method-i-text_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">text_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-value">20</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;text&quot; id=&quot;post_title&quot; name=&quot;post[title]&quot; size=&quot;20&quot; value=&quot;#{@post.title}&quot; /&gt;</span>

<span class="ruby-identifier">text_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;create_input&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;text&quot; id=&quot;post_title&quot; name=&quot;post[title]&quot; value=&quot;#{@post.title}&quot; class=&quot;create_input&quot; /&gt;</span>

<span class="ruby-identifier">text_field</span>(:<span class="ruby-identifier">session</span>, :<span class="ruby-identifier">user</span>, <span class="ruby-identifier">onchange</span><span class="ruby-operator">:</span> <span class="ruby-node">&quot;if ($('#session_user').val() === 'admin') { alert('Your login can not be admin!'); }&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;text&quot; id=&quot;session_user&quot; name=&quot;session[user]&quot; value=&quot;#{@session.user}&quot; onchange=&quot;if ($('#session_user').val() === 'admin') { alert('Your login can not be admin!'); }&quot;/&gt;</span>

<span class="ruby-identifier">text_field</span>(:<span class="ruby-identifier">snippet</span>, :<span class="ruby-identifier">code</span>, <span class="ruby-identifier">size</span><span class="ruby-operator">:</span> <span class="ruby-value">20</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'code_input'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;text&quot; id=&quot;snippet_code&quot; name=&quot;snippet[code]&quot; size=&quot;20&quot; value=&quot;#{@snippet.code}&quot; class=&quot;code_input&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-text_field_source')" id="l_method-i-text_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L770" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-text_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 770</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">text_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">TextField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_field">
            
              <b>time_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-time_field" name="method-i-time_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “time”.</p>

<p>The default value is generated by trying to call <code>strftime</code> with
“%T.%L” on the objects’s value. It is still possible to override that by
passing the “value” option.</p>

<h3 id="method-i-time_field-label-Options">Options</h3>
<ul><li>
<p>Accepts same options as time_field_tag</p>
</li></ul>

<h3 id="method-i-time_field-label-Example">Example</h3>

<pre class="ruby"><span class="ruby-identifier">time_field</span>(<span class="ruby-string">&quot;task&quot;</span>, <span class="ruby-string">&quot;started_at&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;task_started_at&quot; name=&quot;task[started_at]&quot; type=&quot;time&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_field_source')" id="l_method-i-time_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1027" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1027</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">TimeField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-url_field">
            
              <b>url_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-url_field" name="method-i-url_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “url”.</p>

<pre class="ruby"><span class="ruby-identifier">url_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;homepage&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_homepage&quot; name=&quot;user[homepage]&quot; type=&quot;url&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-url_field_source')" id="l_method-i-url_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1104" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-url_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1104</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">url_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">UrlField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-week_field">
            
              <b>week_field</b>(object_name, method, options = {})
            
            <a href="FormHelper.html#method-i-week_field" name="method-i-week_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a <a href="FormHelper.html#method-i-text_field">#text_field</a> of
type “week”.</p>

<pre class="ruby"><span class="ruby-identifier">week_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;week&quot; /&gt;</span>
</pre>

<p>The default value is generated by trying to call <code>strftime</code> with
“%Y-W%W” on the object’s value, which makes it behave as expected for
instances of <a href="../../DateTime.html">DateTime</a> and <a
href="../../ActiveSupport/TimeWithZone.html">ActiveSupport::TimeWithZone</a>.</p>

<pre class="ruby"><span class="ruby-ivar">@user</span>.<span class="ruby-identifier">born_on</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1984</span>, <span class="ruby-value">5</span>, <span class="ruby-value">12</span>)
<span class="ruby-identifier">week_field</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;born_on&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input id=&quot;user_born_on&quot; name=&quot;user[born_on]&quot; type=&quot;date&quot; value=&quot;1984-W19&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-week_field_source')" id="l_method-i-week_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1095" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-week_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1095</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">week_field</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">WeekField</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    